package com.zhkj.txg.module.cart.model

import com.zhkj.lib.http.BaseManager
import com.zhkj.lib.http.BaseResponse
import com.zhkj.lib.http.ResponseSubscribeListener
import com.zhkj.lib.http.SubscribeListener
import com.zhkj.txg.module.cart.entity.CartNumberChangeResponse
import com.zhkj.txg.module.cart.entity.CartResponse
import com.zhkj.txg.module.home.entity.HotGoodsResponse
import io.reactivex.disposables.Disposable

class CartManager : BaseManager<CartApi>(CartApi::class.java) {
    /**
     * 获取购物车列表
     */
    fun getCart(
        token: String,
        listener: SubscribeListener<CartResponse>
    ): Disposable {
        val cart = apiService.getCart(token)
        return subscribe(cart, ResponseSubscribeListener(listener))
    }

    /**
     * 获取购物车列表
     */
    fun getCartNew(
        map: Map<String, String>,
        listener: SubscribeListener<CartResponse>
    ): Disposable {
        val cart = apiService.getCartNew(map)
        return subscribe(cart, ResponseSubscribeListener(listener))
    }

    /**
     * 获取热门商品
     */
    fun hotGoods(
        token: String,
        page: Int,
        numb: Int,
        listener: SubscribeListener<HotGoodsResponse>
    ): Disposable {
        val hotGoods = apiService.hotGoods(token, page, numb)
        return subscribe(hotGoods, ResponseSubscribeListener(listener))
    }

    /**
     * 改变购物车商品数量
     */
    fun changeCartNumber(
        map: Map<String, String>,
        listener: SubscribeListener<CartNumberChangeResponse>
    ): Disposable {
        val changeCartNumber = apiService.changeCartNumber(map)
        return subscribe(changeCartNumber, ResponseSubscribeListener(listener))
    }

    /**
     * 删除购物车商品
     */
    fun deleteCart(
        token: String, CartIds: String,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val deleteCart = apiService.deleteCart(token, CartIds)
        return subscribe(deleteCart, ResponseSubscribeListener(listener))
    }
    fun deleteCart(
        token: String, CartIds: MutableList<String>,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val deleteCart = apiService.deleteCart(token, CartIds)
        return subscribe(deleteCart, ResponseSubscribeListener(listener))
    }
}